import { Subject } from 'rxjs';
import PositionedSentence from '../model/PositionedSentence';
import { sentenceDB } from '../SentenceStorage';

export type SentenceOperationsSignal = 'ADD' | 'REMOVE';

export default class SentenceOperations {
  private __subject: Subject<SentenceOperationsSignal>;

  constructor() {
    this.__subject = new Subject<SentenceOperationsSignal>();
  }

  async addSentence(sentence: PositionedSentence) {
    await sentenceDB.addSentence(sentence);
    this.subject.next('ADD');
  }

  async deleteSentenceByRemark(remark: string) {
    await sentenceDB.deleteByRemark(remark);
    this.subject.next('REMOVE');
  }

  get subject(): Subject<SentenceOperationsSignal> {
    return this.__subject;
  }
}
